/**
    @author: ASUS
    @date: 2021/2/19
    @Describe:
**/
package main

import (
	"flag"
	k "logprocess/global/kernel"
	"logprocess/global/monitor"
	"time"
)

func main() {
	var path, influxDb string

	//从控制台获取
	flag.StringVar(&path, "path", "C:\\Users\\ASUS\\Desktop\\access.log", "readpath")

	flag.StringVar(&influxDb, "influxDb", "http://113.31.126.131:8086@root@Ywd213886@test", "influxDb")

	flag.Parse() //解析参数

	r := &k.ReadFromFile{
		Path: path,
	}
	w := &k.WriteToDB{
		InfluxDBDsn: influxDb,
	}

	lp := &k.LogProcess{
		Rc:    make(chan []byte, 200), //初始化有缓存的chan ，读取比解析快，有可能会阻塞程序
		Wc:    make(chan *k.Message, 200),
		Read:  r,
		Write: w,
	}

	go lp.Read.Reads(lp.Rc) //读取器 读取速度快

	for i := 0; i < 2; i++ {
		go lp.Process() //处理器 需要处理，多开几个协程
	}

	for i := 0; i < 4; i++ {
		go lp.Write.Writes(lp.Wc) //写入数据库 需要时间，所以多开几个协程
	}

	//监控整个程序
	m := &monitor.Monitor{
		StartTime: time.Now(),
		Data:      monitor.SystemInfo{},
	}

	m.Start(lp) //阻塞
}

/**
	r := regexp.MustCompile(`([\d\.]+)\s+([^ \[]+)\s+([^ \[]+)\s+\[([^\[\]]+)\]\s+\"([^"]+)\"\s+(\d{3})\s+(\d+)\s+([^ \[]+)\s+\"([^"]+)\"\s+\"([^"]+)\"\s+\"(.*?)\"\s+\"([\d\.-]+)\"\s+\"([\d\.-]+)\"`)

	ret := r.FindStringSubmatch(`117.89.195.195 - - [19/Feb/2021:14:52:51 +0800] "GET / HTTP/1.1" 304 0 - "http://www.zxxtyzy.com/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.150 Safari/537.36 Edg/88.0.705.63" "-" "-" "0.000"
`)

	fmt.Println(ret[12])

*/
